package yijy.company.singletonExample;

/**
 * Created by yijy on 2017/6/14.
 * Java单例——双重校验
 */
public class SingletonDoubleSafeModel {
    private volatile static SingletonDoubleSafeModel instance = null;
    private SingletonDoubleSafeModel(){}

    public static SingletonDoubleSafeModel getInstance(){
        if(instance == null){
            synchronized (SingletonDoubleSafeModel.class){
                if(instance == null){
                    instance = new SingletonDoubleSafeModel();
                }
            }
        }
        return instance;
    }

    public static String getInstance1(){
//        if(instance == null){
//            synchronized (SingletonDoubleSafeModel.class){
//                if(instance == null){
//                    instance = new SingletonDoubleSafeModel();
//                }
//            }
//        }
        return "11";
    }

    public static void main(String[] args) {
//        SingletonB singletonB = getSingletonB();
//        System.out.println(singletonB);
        try{
            System.out.println(args[args.length]);
        }catch (ArrayIndexOutOfBoundsException e){
        }
    }
}

class SingletonB{
    private volatile static SingletonB singletonB = null;
    private SingletonB(){}

    public static SingletonB getSingletonB(){
        if(singletonB == null){
            synchronized (SingletonB.class){
                if(singletonB == null){
                    singletonB = new SingletonB();
                }
            }
        }
        return singletonB;
    }
}
